<?php
	date_default_timezone_set('Australia/Sydney');

	$refNum = $_POST["refNum"];
	$firstname = $_POST['firstname'];
	$surname = $_POST['surname'];
	$age = $_POST['age'];
	$phone = $_POST['phone'];
	$address = $_POST['address'];
	$complaint = $_POST['complaint'];
	$crossStreet = $_POST['crossStreet'];
	$email = $_POST["email"];
	$hour = time() / 3600 % 24;
    $minute = time() / 60 % 60;
	$subject = $refNum . '/' . $surname . '/' . $age . '/' . $phone;
	$message = $hour . ':' . $minute . '/' . $firstname . ' ' . $surname . '/' . $address . '/' . $complaint . '#' . $crossStreet;
	if(isset($refNum) && isset($firstname) && isset($age) && isset($phone) && isset($address) && isset($complaint) && isset($crossStreet) && isset($email))
	{
		mail("ccorscadden118@gmail.com", "successful POST", "foo");
		mail("ccorscadden118@gmail.com", $subject, $message);
		connect_database();
	}
	else
		mail("ccorscadden118@gmail.com", "failed POST", "foo");


	function connect_database(){
		$mysqli = new mysqli('localhost', 'root', '', 'gluphien');
		//echo $DBConnect;
		if ($mysqli->connect_errno)
			echo "<p>Connection Failed.</p>";
		else
		{
			echo "this is good";
		}
		$SQLstring = "INSERT INTO `request` (`referenceNumber`, `firstName`, `surname`, `age`, `phoneNumber`, `address`, `complaint`, `crossStreet`, `email`) 
			VALUES ('" . $GLOBALS["refNum"] . "', '" . $GLOBALS["firstname"] . "', '" . $GLOBALS["surname"] . "', '" . $GLOBALS["age"] . "', '" . $GLOBALS["phone"] . "', '" . $GLOBALS["address"] . "', '" . $GLOBALS["complaint"] . "', '" . $GLOBALS["crossStreet"] . "', '" . $GLOBALS["email"] . "')";
		if (mysqli_query($mysqli, $SQLstring) === TRUE) {
			echo "<p> success users";
		}
		else
		{
			echo $mysqli->error;
		}
		$mysqli->close();
	}
?>